//
//  DHCUtil.m
//  Trading365
//
//  Created by Jason on 12-3-29.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "DHCUtil.h"

@implementation DHCUtil

+(NSString *)dataFilePath
{
    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentDirectory = [path objectAtIndex:0];
    
    return [documentDirectory stringByAppendingPathComponent:KFileName_login];
}

//+(NSString *)settingsFilePath
//{
//    NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
//    NSString *documentDirectory = [path objectAtIndex:0];
//    
//    return [documentDirectory stringByAppendingPathComponent:KFileName_settings];    
//}

+(NSString *)getDateFromString:(NSString *)strDate
{
    //2012-03-13 00:00:00.0
    return [strDate substringToIndex:10];
}
//20120328T00:00:00
+(NSString *)getDateFromString1:(NSString *)strDate
{
    //20120326T00:00:00
    return [strDate substringToIndex:8];
}

+(NSString *)getCurrentDateTime
{
    NSString* date;
    NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"YYYY-MM-dd hh:mm:ss"];
    date = [formatter stringFromDate:[NSDate date]];
    [formatter release];
    return date;
}

+(NSString *)getCurrentDate
{
    NSString* date;
    NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"YYYY-MM-dd"];
    date = [formatter stringFromDate:[NSDate date]];
    [formatter release];
    return date;
}

+(NSString *)getCurrentTime
{
    NSString* date;
    NSDateFormatter* formatter = [[NSDateFormatter alloc]init];
    [formatter setDateFormat:@"hh:mm:ss"];
    date = [formatter stringFromDate:[NSDate date]];
    [formatter release];
    return date;
}

+(NSString *)getDeviceType
{
    return [[UIDevice currentDevice] model];
}

+(BOOL) checkIsNum:(NSString *) strNum
{
    NSString *regex = @"[0-9]*";
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    
    return [predicate evaluateWithObject:strNum];

}

//+ (BOOL) connectedToNetwork
//{
//    // Create zero addy
//    struct sockaddr_in zeroAddress;
//    bzero(&zeroAddress, sizeof(zeroAddress));
//    zeroAddress.sin_len = sizeof(zeroAddress);
//    zeroAddress.sin_family = AF_INET;
//    
//    // Recover reachability flags
//    SCNetworkReachabilityRef defaultRouteReachability = SCNetworkReachabilityCreateWithAddress(NULL, (struct sockaddr *)&zeroAddress);    
//    CFRelease(defaultRouteReachability);
//    
//    SCNetworkReachabilityFlags flags;
//    
//    BOOL didRetrieveFlags = SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags);
//    if (!didRetrieveFlags) 
//    {
//        printf("Error. Could not recover network reachability flags\n");
//        return 0;
//    }
//    
//    BOOL isReachable = flags & kSCNetworkFlagsReachable;
//    BOOL needsConnection = flags & kSCNetworkFlagsConnectionRequired;
//    // BOOL isEDGE = flags & kSCNetworkReachabilityFlagsIsWWAN;
//    return (isReachable && !needsConnection) ? YES : NO;
//}

@end
